package com.qf.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class DateUtil {

    /**
     * 根据索引获得对应的时间场次
     * 0 - 当前场
     * 1 - 下一场
     * 2 - 下下一场
     *
     * @return
     */
    public static String getTimeByIndex(int index){

        //获得日历对象 - 11:27
        Calendar calendar = Calendar.getInstance();
        //获得当前的小时
        int h = calendar.get(Calendar.HOUR_OF_DAY);//11
        if (h % 2 != 0) {
            h -= 1;
        }
        //h - 10

        //设置当前场次的时间
        calendar.set(Calendar.HOUR_OF_DAY, h + (index * 2));
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
    }
}
